﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TankBattle.Models
{
    public  class GameObject
    {
        #region Variable

        protected Texture2D texture;
        protected Vector2 position;
        protected int life;
        protected int width;
        protected int height;
        protected bool stop;
        protected bool undead;

        #endregion

        #region Contruction

        public GameObject()
        { }
        public GameObject(Texture2D texture, Vector2 position, int width, int height)
        {
            Intallization(texture, position, width, height);
        }
        public GameObject(Vector2 position)
        {
            Intallization(texture, position,Constant.OBSTRUCTION_WIDTH,Constant.OBSTRUCTION_HEIGHT);
        }

        #endregion

        #region Properties

        public virtual Rectangle Polygon
        {
            get 
            {
                int tempX = (int)position.X;
                int tempY = (int)position.Y;
                return new Rectangle(
                    tempX + 1, 
                    tempY + 1, 
                    width - 1, 
                    height - 1);
            }
        }
        public Vector2 Position
        {
            get
            {
                return position;
            }
        }
        public virtual bool UnDead
        {
            get
            {
                return undead;
            }
        }
        public virtual bool Hidden
        {
            get { return false; }
        }
        public virtual Vector2 GetBoomPosition()
        {
            return
                new Vector2(
                    position.X - Math.Abs(width - Constant.BOOM_SIZE),
                    position.Y - Math.Abs(height - Constant.BOOM_SIZE));
        }
        #endregion

        #region Function 
        //testCrashLimit kiểm tra xem đối tượng có nằm ngoài màn hình không
        public virtual bool testCrashLimit(Vector2 position)
        {
            if (position.X < 0 || position.X > Constant.BOX_WIDTH - width
                || position.Y < 0 || position.Y > Constant.BOX_HEIGHT - height)
                return true;
            else
                return false;
        }
        //Update cập nhật trạng thái của đối tượng.
        public virtual bool Update()
        {
            return true;
        } 
        //Draw vẽ đối tượng.
        public virtual void Draw(SpriteBatch spriteBatch)
        { }
        //Killed giết đối tượng.
        public virtual bool Killed(int damage)
        {
            if ((life - damage) <= 0)
                return true;
            else
                return false;
        }
        //Intallization khởi tạo ban đầu cho đối tượng.
        protected virtual void Intallization(Texture2D texture, Vector2 position, int width, int height)
        {
            stop = false;
            this.position = position;
            this.width = width;
            this.height = height;
            this.texture = texture;
        }
        //Thiết lập tọa độ cho đối tượng
        public virtual void SetPosition(Vector2 position)
        {
            this.position = position;
        }
        public virtual void SetStop(bool stopState)
        {
            stop = stopState;
        }
        public virtual void SetUnDead(bool undead)
        {
            this.undead = undead;
        }
        #endregion

    }
}
